import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import WorkDetail from '../view/work-detail.vue'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Home',
    component: () => import('../view/index.vue'),
    meta: {
      title: 'AI助手'
    }
  },
  {
    path: '/history-chat',
    name: 'HistoryChat',
    component: () => import('../view/history-chat.vue'),
  },
  {
    path: '/assistant',
    name: 'Assistant',
    component: () => import('../view/assistant.vue'),
    meta: {
      title: 'AI助手-功能'
    }
  },
  {
    path: '/community',
    name: 'Community',
    component: () => import('../view/community.vue'),
    meta: {
      title: 'AI助手-社区'
    }
  },
  {
    path: '/CreateWork',
    name: 'CreateWork',
    component: () => import('../view/CreateWork.vue'),
    meta: {
      title: 'AI助手-发布作品'
    }
  },
  {
    path: '/work-detail/:id',
    name: 'WorkDetail',
    component: () => import('../view/work-detail.vue'),
    meta: {
      title: 'AI助手-作品详情'
    }
  },
  {
    path: '/index',
    name: 'Index',
    component: () => import('../view/index.vue'),
    meta: {
      title: 'AI助手-对话'
      }
  },
  {
    path: '/author/:id',
    name: 'Author',
    component: () => import('../view/author.vue'),
    meta: {
      title: 'AI助手-创作者'
    }
  },
  {
    path: '/profile',
    name: 'Profile',
    component: () => import('../view/profile.vue'),
    meta: {
      title: '个人主页'
    }
  },
  {
    path: '/settings',
    name: 'Settings',
    component: () => import('../view/settings.vue'),
    meta: {
      title: '设置'
    }
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../view/about.vue'),
    meta: {
      title: '关于我们'
    }
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../view/login.vue'),
    meta: {
      title: '登录'
    }
  },
  {
    path: '/search',
    name: 'Search',
    component: () => import('../view/search.vue'),
    meta: {
      title: '搜索'
    }
  },
  {
    path: '/energy',
    name: 'Energy',
    component: () => import('../view/energy.vue'),
    meta: {
      title: '能量'
    }
  },
  {
    path: '/energy/rules',
    name: 'EnergyRules',
    component: () => import('../view/energy-rules.vue'),
    meta: {
      title: '规则说明'
    }
  },
  {
    path: '/company',
    name: 'Company',
    component: () => import('../view/company.vue'),
    meta: {
      title: '企业介绍'
    }
  },
  {
    path: '/agreement',
    name: 'Agreement',
    component: () => import('../view/agreement.vue'),
    meta: {
      title: '用户协议'
    }
  },
  {
    path: '/privacy',
    name: 'Privacy',
    component: () => import('../view/privacy.vue'),
    meta: {
      title: '隐私政策'
    }
  },
  {
    path: '/feedback',
    name: 'Feedback',
    component: () => import('../view/feedback.vue'),
    meta: {
      title: '意见反馈'
    }
  },
  {
    path: '/auther',
    name: 'Auther',
    component: () => import('../view/auther.vue'),
    meta: {
      title: '自己的作品'
    }
  },
  {
    path: '/mess',
    name: 'Mess',
    component: () => import('../view/mess.vue'),
    meta: {
      title: '消息'
    }
  },
  {
    path: '/draw-chat',
    name: 'DrawChat',
    component: () => import('../view/draw-chat.vue'),
  },
]


const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由前置守卫，用于设置页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title as string
  }
  next()
})

export default router
